package IC.Parser;

/**
 * A class that represents a lexical error, will be thrown by the parser
 * whenever a lexical error will occur.
 * @author nimrod
 *
 */
public class LexicalError extends Exception
{
	private static final long serialVersionUID = -5392794008982394429L;
	
	private int line;
	
	/**
	 *  Constructor for LexicalError.
	 * @param message 
	 * 		The exception's message.
	 */
	public LexicalError(String message)
	{
		this(message, -1);
	}
	
	/**
	 * Constructor for LexicalError
	 * @param message
	 * 		The exception's message.
	 * @param line
	 * 		The line of the token that caused the exception.
	 */
    public LexicalError(String message, int line) {
    	super(message);
    	this.line = line;
    }
    
    /**
     *  getter for line field
     * @return 
     * 		Returns the line of the token that caused the exception.
     */
    public int getLine() {
    	return this.line;
    }
    
    /** returns a string representation of the class
     * @return 
     * 		Returns a string representation of the class.
     */
    public String toString() {
    	return this.line + ": Lexical error: " + this.getMessage();
    }
}

